home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / sunfonts / bdftovfont.c next >
C/C++ Source or Header  |  1992-02-06  |  1KB  |  69 lines

  1. #include <stdio.h>
  2. #include <vfont.h>
  3. #include "Font.h"
  4.  
  5. void bdftovfont(ofp, font)
  6. FILE *ofp;
  7. Font *font;
  8. {
  9.     struct header hdr;
  10.     struct dispatch dsp[NUM_DISPATCH];
  11.     int i, totalbytes;
  12.     Glyph *gp;
  13.     int maxx, maxy;
  14.     
  15.     bzero(&hdr, sizeof hdr);
  16.     bzero(dsp, sizeof dsp);
  17.     
  18.     for (totalbytes= i= 0; i < MAXCHARS; i++) {
  19.     if ((gp= font->glyphs[i]) == 0)
  20.         continue;
  21.     dsp[i].width= gp->width;
  22.     dsp[i].addr= totalbytes;
  23.     if (gp->nbytes > 0) {
  24.         dsp[i].nbytes= gp->nbytes;
  25.         dsp[i].up= gp->up;
  26.         dsp[i].down= gp->down;
  27.         dsp[i].left= gp->left;
  28.         dsp[i].right= gp->right;
  29.     } else {
  30.         dsp[i].nbytes= dsp[i].up= dsp[i].right= 1;
  31.         dsp[i].down= dsp[i].left= 0;
  32.     }
  33.     totalbytes+= dsp[i].nbytes;
  34.     }
  35.  
  36.     hdr.magic= VFONT_MAGIC;
  37.     hdr.size= totalbytes;
  38.     
  39.     MaxExtent(font, &maxx, &maxy);
  40.     hdr.maxx= maxx;
  41.     hdr.maxy= maxy;
  42.     
  43.     fwrite(&hdr, sizeof(struct header), 1, ofp);
  44.     fwrite(dsp, sizeof(struct dispatch), NUM_DISPATCH, ofp);
  45.     
  46.     for (i= 0; i < MAXCHARS; i++) {
  47.     if (gp= font->glyphs[i]) {
  48.         if (gp->nbytes > 0 && gp->bits)
  49.         fwrite(gp->bits, 1, gp->nbytes, ofp);
  50.         else
  51.         fwrite("", 1, 1, ofp);
  52.     }
  53.     }
  54. }
  55.  
  56. main(argc, argv)
  57. int argc;
  58. char *argv[];
  59. {
  60.     Font *fp;
  61.     
  62.     fp= ReadBdf(argv[1]);
  63.     if (fp) {
  64.     FontBBox(fp);
  65.     bdftovfont(stdout, fp);
  66.     }
  67.     exit(0);
  68. }
  69.